1 // ----------------------------------------------------------------------------------------------------------------------
2 // <summary>The Photon Chat Api enables clients to connect to a chat server and communicate with other clients.</summary>
3 // <remarks>ChatClient
is the main class of this api.</remarks>
4 // <copyright company=
"Exit Games GmbH">Photon Chat Api - Copyright (C) 2014 Exit Games GmbH</copyright>
5 // ----------------------------------------------------------------------------------------------------------------------

6
7 namespace
ExitGames.Client.Photon.Chat
8 {
9     
using System.Collections.Generic;
10     
using ExitGames.Client.Photon;
11
12     ///
<summary>
13     ///
Provides basic operations of the Photon Chat server. This internal class is used by public ChatClient.
14     ///
</summary>
15     
internal class ChatPeer : PhotonPeer
16     {
17         
public ChatPeer(IPhotonPeerListener listener, ConnectionProtocol protocol) : base(listener, protocol)
18         {
19         }
20
21         
public bool Connect(string address, ConnectionProtocol protocol)
22         {
23             
if (this.UsedProtocol != protocol)
24             {
25                 
return false;
26             }
27
28             
return true;
29         }
30
31         
public bool AuthenticateOnNameServer(string appId, string appVersion, string region, string userId, AuthenticationValues authValues)
32         {
33             
if (this.DebugOut >= DebugLevel.INFO)
34             {
35                 
this.Listener.DebugReturn(DebugLevel.INFO, "OpAuthenticate()");
36             }
37
38             
var opParameters = new Dictionary<byte, object>();
39
40             opParameters[ParameterCode.AppVersion] = appVersion;
41             opParameters[ParameterCode.ApplicationId] = appId;
42             opParameters[ParameterCode.Region] = region;
43
44             
if (!string.IsNullOrEmpty(userId))
45             {
46                 opParameters[ParameterCode.UserId] = userId;
47             }
48
49             
if (authValues != null && authValues.AuthType != CustomAuthenticationType.None)
50             {
51                 opParameters[ParameterCode.ClientAuthenticationType] = (
byte)authValues.AuthType;
52                 
if (!string.IsNullOrEmpty(authValues.Secret))
53                 {
54                     opParameters[ParameterCode.Secret] = authValues.Secret;
55                 }
56                 
else
57                 {
58                     
if (!string.IsNullOrEmpty(authValues.AuthParameters))
59                     {
60                         opParameters[ParameterCode.ClientAuthenticationParams] = authValues.AuthParameters;
61                     }
62                     
if (authValues.AuthPostData != null)
63                     {
64                         opParameters[ParameterCode.ClientAuthenticationData] = authValues.AuthPostData;
65                     }
66                 }
67             }
68
69             
return this.OpCustom((byte)ChatOperationCode.Authenticate, opParameters, true, (byte)0, this.IsEncryptionAvailable);
70         }
71     }

72
73     ///
<summary>
74     ///
Options for optional "Custom Authentication" services used with Photon. Used by OpAuthenticate after connecting to Photon.
75     ///
</summary>
76     
public enum CustomAuthenticationType : byte
77     {

78         ///
<summary>Use a custom authentification service. Currently the only implemented option.</summary>
79         Custom =
0,
80
81         ///
<summary>Authenticates users by their Steam Account. Set auth values accordingly!</summary>
82         Steam =
1,
83
84         ///
<summary>Authenticates users by their Facebook Account. Set auth values accordingly!</summary>
85         Facebook =
2,
86
87         ///
<summary>Disables custom authentification. Same as not providing any AuthenticationValues for connect (more precisely for: OpAuthenticate).</summary>
88         None =
byte.MaxValue
89     }

90
91
92     ///
<summary>
93     ///
Container for "Custom Authentication" values in Photon (default: user and token). Set AuthParameters before connecting - all else is handled.
94     ///
</summary>
95     ///
<remarks>
96     ///
Custom Authentication lets you verify end-users by some kind of login or token. It sends those
97     ///
values to Photon which will verify them before granting access or disconnecting the client.
98     ///
99     ///
The Photon Cloud Dashboard will let you enable this feature and set important server values for it.
100     ///
https://cloud.exitgames.com/dashboard
101     ///
</remarks>
102     
public class AuthenticationValues
103     {

104         ///
<summary>The type of custom authentication provider that should be used. Currently only "Custom" or "None" (turns this off).</summary>
105         
public CustomAuthenticationType AuthType = CustomAuthenticationType.Custom;
106
107         ///
<summary>This string must contain any (http get) parameters expected by the used authentication service. By default, username and token.</summary>
108         ///
<remarks>Standard http get parameters are used here and passed on to the service that's defined in the server (Photon Cloud Dashboard).</remarks>
109         
public string AuthParameters;
110
111         ///
<summary>After initial authentication, Photon provides a secret for this client / user, which is subsequently used as (cached) validation.</summary>
112         
public string Secret;
113
114         ///
<summary>Data to be passed-on to the auth service via POST. Default: null (not sent). Either string or byte[] (see setters).</summary>
115         
public object AuthPostData { get; private set; }
116
117         ///
<summary>Sets the data to be passed-on to the auth service via POST.</summary>
118         ///
<param name="stringData">Binary token / auth-data to pass on. Empty string will set AuthPostData to null.</param>
119         
public virtual void SetAuthPostData(string stringData)
120         {
121             
this.AuthPostData = (string.IsNullOrEmpty(stringData)) ? null : stringData;
122         }

123
124         ///
<summary>Sets the data to be passed-on to the auth service via POST.</summary>
125         ///
<param name="byteData">Binary token / auth-data to pass on.</param>
126         
public virtual void SetAuthPostData(byte[] byteData)
127         {
128             
this.AuthPostData = byteData;
129         }

130
131         ///
<summary>Creates the default parameter-string from a user- and token-value, escaping both. Alternatively set AuthParameters directly.</summary>
132         ///
<remarks>The default parameter string is: "username={user}&token={token}"</remarks>
133         ///
<param name="user">Name or other end-user ID used in custom authentication service.</param>
134         ///
<param name="token">Token provided by authentication service to be used on initial "login" to Photon.</param>
135         
public virtual void SetAuthParameters(string user, string token)
136         {
137             
this.AuthParameters = "username=" + System.Uri.EscapeDataString(user) + "&token=" + System.Uri.EscapeDataString(token);
138         }
139     }
140
141     
public class ParameterCode
142     {
143         
public const byte ApplicationId = 224;
144         ///
<summary>(221) Internally used to establish encryption</summary>
145         
public const byte Secret = 221;
146         
public const byte AppVersion = 220;
147         ///
<summary>(217) This key's (byte) value defines the target custom authentication type/service the client connects with. Used in OpAuthenticate</summary>
148         
public const byte ClientAuthenticationType = 217;
149
150         ///
<summary>(216) This key's (string) value provides parameters sent to the custom authentication type/service the client connects with. Used in OpAuthenticate</summary>
151         
public const byte ClientAuthenticationParams = 216;
152
153         ///
<summary>(214) This key's (string or byte[]) value provides parameters sent to the custom authentication service setup in Photon Dashboard. Used in OpAuthenticate</summary>
154         
public const byte ClientAuthenticationData = 214;
155         ///
<summary>(210) Used for region values in OpAuth and OpGetRegions.</summary>
156         
public const byte Region = 210;
157         ///
<summary>(230) Address of a (game) server to use.</summary>
158         
public const byte Address = 230;
159         ///
<summary>(225) User's ID</summary>
160         
public const byte UserId = 225;
161     }

162     ///
<summary>
163     ///
ErrorCode defines the default codes associated with Photon client/server communication.
164     ///
</summary>
165     
public class ErrorCode
166     {

167         ///
<summary>(0) is always "OK", anything else an error or specific situation.</summary>
168         
public const int Ok = 0;
169
170         
// server - Photon low(er) level: <= 0
171
172         ///
<summary>
173         ///
(-3) Operation can't be executed yet (e.g. OpJoin can't be called before being authenticated, RaiseEvent cant be used before getting into a room).
174         ///
</summary>
175         ///
<remarks>
176         ///
Before you call any operations on the Cloud servers, the automated client workflow must complete its authorization.
177         ///
In PUN, wait until State is: JoinedLobby (with AutoJoinLobby = true) or ConnectedToMaster (AutoJoinLobby = false)
178         ///
</remarks>
179         
public const int OperationNotAllowedInCurrentState = -3;
180
181         ///
<summary>(-2) The operation you called is not implemented on the server (application) you connect to. Make sure you run the fitting applications.</summary>
182         
public const int InvalidOperationCode = -2;
183
184         ///
<summary>(-1) Something went wrong in the server. Try to reproduce and contact Exit Games.</summary>
185         
public const int InternalServerError = -1;
186
187         
// server - PhotonNetwork: 0x7FFF and down
188         
// logic-level error codes start with short.max
189
190         ///
<summary>(32767) Authentication failed. Possible cause: AppId is unknown to Photon (in cloud service).</summary>
191         
public const int InvalidAuthentication = 0x7FFF;
192
193         ///
<summary>(32766) GameId (name) already in use (can't create another). Change name.</summary>
194         
public const int GameIdAlreadyExists = 0x7FFF - 1;
195
196         ///
<summary>(32765) Game is full. This rarely happens when some player joined the room before your join completed.</summary>
197         
public const int GameFull = 0x7FFF - 2;
198
199         ///
<summary>(32764) Game is closed and can't be joined. Join another game.</summary>
200         
public const int GameClosed = 0x7FFF - 3;
201
202         ///
<summary>(32762) Not in use currently.</summary>
203         
public const int ServerFull = 0x7FFF - 5;
204
205         ///
<summary>(32761) Not in use currently.</summary>
206         
public const int UserBlocked = 0x7FFF - 6;
207
208         ///
<summary>(32760) Random matchmaking only succeeds if a room exists thats neither closed nor full. Repeat in a few seconds or create a new room.</summary>
209         
public const int NoRandomMatchFound = 0x7FFF - 7;
210
211         ///
<summary>(32758) Join can fail if the room (name) is not existing (anymore). This can happen when players leave while you join.</summary>
212         
public const int GameDoesNotExist = 0x7FFF - 9;
213
214         ///
<summary>(32757) Authorization on the Photon Cloud failed becaus the concurrent users (CCU) limit of the app's subscription is reached.</summary>
215         ///
<remarks>
216         ///
Unless you have a plan with "CCU Burst", clients might fail the authentication step during connect.
217         ///
Affected client are unable to call operations. Please note that players who end a game and return
218         ///
to the master server will disconnect and re-connect, which means that they just played and are rejected
219         ///
in the next minute / re-connect.
220         ///
This is a temporary measure. Once the CCU is below the limit, players will be able to connect an play again.
221         ///
222         ///
OpAuthorize is part of connection workflow but only on the Photon Cloud, this error can happen.
223         ///
Self-hosted Photon servers with a CCU limited license won't let a client connect at all.
224         ///
</remarks>
225         
public const int MaxCcuReached = 0x7FFF - 10;
226
227         ///
<summary>(32756) Authorization on the Photon Cloud failed because the app's subscription does not allow to use a particular region's server.</summary>
228         ///
<remarks>
229         ///
Some subscription plans for the Photon Cloud are region-bound. Servers of other regions can't be used then.
230         ///
Check your master server address and compare it with your Photon Cloud Dashboard's info.
231         ///
https://cloud.exitgames.com/dashboard
232         ///
233         ///
OpAuthorize is part of connection workflow but only on the Photon Cloud, this error can happen.
234         ///
Self-hosted Photon servers with a CCU limited license won't let a client connect at all.
235         ///
</remarks>
236         
public const int InvalidRegion = 0x7FFF - 11;
237
238         ///
<summary>
239         ///
(32755) Custom Authentication of the user failed due to setup reasons (see Cloud Dashboard) or the provided user data (like username or token). Check error message for details.
240         ///
</summary>
241         
public const int CustomAuthenticationFailed = 0x7FFF - 12;
242     }
243
244 }


----------------------------------------------------------------------------------------------------------------------

The Photon Chat Api enables clients to connect to a chat server and communicate with other clients.

ChatClient is the main class of this api.

Photon Chat Api - Copyright (C) 2014 Exit Games GmbH

----------------------------------------------------------------------------------------------------------------------

Provides basic operations of the Photon Chat server. This internal class is used by public ChatClient.

Options for optional "Custom Authentication" services used with Photon. Used by OpAuthenticate after connecting to Photon.

Use a custom authentification service. Currently the only implemented option.

Authenticates users by their Steam Account. Set auth values accordingly!

Authenticates users by their Facebook Account. Set auth values accordingly!

Disables custom authentification. Same as not providing any AuthenticationValues for connect (more precisely for: OpAuthenticate).

Container for "Custom Authentication" values in Photon (default: user and token). Set AuthParameters before connecting - all else is handled.

Custom Authentication lets you verify end-users by some kind of login or token. It sends those

values to Photon which will verify them before granting access or disconnecting the client.

The Photon Cloud Dashboard will let you enable this feature and set important server values for it.

https:cloud.exitgames.comdashboard

The type of custom authentication provider that should be used. Currently only "Custom" or "None" (turns this off).

This string must contain any (http get) parameters expected by the used authentication service. By default, username and token.

Standard http get parameters are used here and passed on to the service that's defined in the server (Photon Cloud Dashboard).

After initial authentication, Photon provides a secret for this client user, which is subsequently used as (cached) validation.

Data to be passed-on to the auth service via POST. Default: null (not sent). Either string or byte[] (see setters).

Sets the data to be passed-on to the auth service via POST.

Binary token auth-data to pass on. Empty string will set AuthPostData to null.

Sets the data to be passed-on to the auth service via POST.

Binary token auth-data to pass on.

Creates the default parameter-string from a user- and token-value, escaping both. Alternatively set AuthParameters directly.

The default parameter string is: "username={user}&token={token}"

Name or other end-user ID used in custom authentication service.

Token provided by authentication service to be used on initial "login" to Photon.

(221) Internally used to establish encryption

(217) This key's (byte) value defines the target custom authentication typeservice the client connects with. Used in OpAuthenticate

(216) This key's (string) value provides parameters sent to the custom authentication typeservice the client connects with. Used in OpAuthenticate

(214) This key's (string or byte[]) value provides parameters sent to the custom authentication service setup in Photon Dashboard. Used in OpAuthenticate

(210) Used for region values in OpAuth and OpGetRegions.

(230) Address of a (game) server to use.

(225) User's ID

ErrorCode defines the default codes associated with Photon clientserver communication.

(0) is always "OK", anything else an error or specific situation.

server - Photon low(er) level: <= 0

(-3) Operation can't be executed yet (e.g. OpJoin can't be called before being authenticated, RaiseEvent cant be used before getting into a room).

Before you call any operations on the Cloud servers, the automated client workflow must complete its authorization.

In PUN, wait until State is: JoinedLobby (with AutoJoinLobby = true) or ConnectedToMaster (AutoJoinLobby = false)

(-2) The operation you called is not implemented on the server (application) you connect to. Make sure you run the fitting applications.

(-1) Something went wrong in the server. Try to reproduce and contact Exit Games.

server - PhotonNetwork: 0x7FFF and down

logic-level error codes start with short.max

(32767) Authentication failed. Possible cause: AppId is unknown to Photon (in cloud service).

(32766) GameId (name) already in use (can't create another). Change name.

(32765) Game is full. This rarely happens when some player joined the room before your join completed.

(32764) Game is closed and can't be joined. Join another game.

(32762) Not in use currently.

(32761) Not in use currently.

(32760) Random matchmaking only succeeds if a room exists thats neither closed nor full. Repeat in a few seconds or create a new room.

(32758) Join can fail if the room (name) is not existing (anymore). This can happen when players leave while you join.

(32757) Authorization on the Photon Cloud failed becaus the concurrent users (CCU) limit of the app's subscription is reached.

Unless you have a plan with "CCU Burst", clients might fail the authentication step during connect.

Affected client are unable to call operations. Please note that players who end a game and return

to the master server will disconnect and re-connect, which means that they just played and are rejected

in the next minute re-connect.

This is a temporary measure. Once the CCU is below the limit, players will be able to connect an play again.

OpAuthorize is part of connection workflow but only on the Photon Cloud, this error can happen.

Self-hosted Photon servers with a CCU limited license won't let a client connect at all.

(32756) Authorization on the Photon Cloud failed because the app's subscription does not allow to use a particular region's server.

Some subscription plans for the Photon Cloud are region-bound. Servers of other regions can't be used then.

Check your master server address and compare it with your Photon Cloud Dashboard's info.

https:cloud.exitgames.comdashboard

OpAuthorize is part of connection workflow but only on the Photon Cloud, this error can happen.

Self-hosted Photon servers with a CCU limited license won't let a client connect at all.

(32755) Custom Authentication of the user failed due to setup reasons (see Cloud Dashboard) or the provided user data (like username or token). Check error message for details.




Trò chơi Tic-Tac-Toe, game đánh caro full source code 53.529 lượt xem

Gõ tìm kiếm nhanh...